package com.hardson.toolkit.swing.print;

import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.Graphics;

import lombok.Setter;

public class PreviewHeader extends Component {
	private static final long serialVersionUID = -1741188309769027249L;

	private PreviewArea previewArea;

	private Preview preview;

	@Setter
	private boolean paintable;

	public PreviewHeader(final Preview preview, final PreviewArea previewArea) {
		this.preview = preview;
		this.previewArea = previewArea;
	}

	@Override
	public void paint(final Graphics g) {
		if (this.paintable) {
			g.setColor(Color.GRAY);
			StringBuilder sb = new StringBuilder(this.previewArea.getPageIndex() + 1);
			sb.append("/");
			sb.append(this.preview.getPageBreaks().length + 1);
			sb.append(" pages (Click left mouse button to preview next page; right to previous)");
			g.drawString(sb.toString(), 10, 15);
		}
	}

	@Override
	public Dimension getPreferredSize() {
		return new Dimension(super.getPreferredSize().width, 20);
	}
}
